﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace PankowGame13
{
    public enum EnemyType
    {
        Kobold,
        Spider
    }

    class Enemy
    {
        public Texture2D enemySprite { get; set; }
        public Rectangle enemyRect { get; set; }
        public int enemyHealth { get; set; }
        public int enemyDefense { get; set; }
        public int enemyAttack { get; set; }
        public EnemyType type { get; set; }
        public bool isVisible { get; set; }
        public string status { get; set; }
        public Vector2 startingPos { get; set; }
        bool isMovingRight = false;
        private int multiplier { get; set; }

        public Enemy(EnemyType eType, int level, string textureName, ContentManager content, Vector2 position, Vector2 size)
        {
            multiplier = 2; 
            isVisible = true;
            startingPos = position;
            enemySprite = content.Load<Texture2D>(textureName);
            enemyRect = new Rectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y);
            type = eType;
            status = "Angry";
            
            Random rand = new Random();
            if (level > 0 && level <= 5)
            {
                enemyHealth = rand.Next(1, 6) * 10 + (level * 2);
                enemyDefense = rand.Next(0, 2) * 10 + (level * 2);
                enemyAttack = rand.Next(7, 36) + 20 + (level * 2);
            }
            if (level > 5 && level <= 10)
            {
                enemyHealth = rand.Next(5, 11) * 10 + (level * 4) + 200;
                enemyDefense = rand.Next(2, 3) * 10 + (level * 4);
                enemyAttack = rand.Next(15, 45) + 25 + (level * 4) + 10;
            }
            if (level > 10 && level <= 15)
            {
                enemyHealth = rand.Next(10, 16) * 12 + (level * 6) + 200;
                enemyDefense = rand.Next(3, 5) * 12 + (level * 6);
                enemyAttack = rand.Next(25, 55) + 35 + (level * 6);
            }
            if (level > 15 && level <= 20)
            {
                enemyHealth = rand.Next(15, 21) * 15 + (level * 8) + 200;
                enemyDefense = rand.Next(3, 9) * 15 + (level * 8);
                enemyAttack = rand.Next(35, 66) + 45 + (level * 8) + 5;
            }
            if (level > 20 && level <= 50)
            {
                enemyHealth = rand.Next(15, 21) * 15 + (level * 10) * multiplier + 500;
                enemyDefense = rand.Next(3, 9) * 15 + (level * 10) * multiplier + 500;
                enemyAttack = rand.Next(35, 66) + 45 + (level * 10) * multiplier;
            }
            if (level > 50)
            {
                enemyHealth = rand.Next(25, 46) * 35 + (level * 12) * (multiplier + level);
                enemyDefense = rand.Next(5, 13) * 25 + (level * 12) * (multiplier + level);
                enemyAttack = rand.Next(80, 121) + 65 + (level * 12) * (multiplier + level);
            }

            System.Threading.Thread.Sleep(300);
        }

        public void Update(ref Player thePlayer)
        {
            if (enemyRect.X >= startingPos.X && !isMovingRight)
            {
                enemyRect = new Rectangle(enemyRect.X - 1, enemyRect.Y, enemyRect.Width, enemyRect.Height);
            }

            if (enemyRect.X <= startingPos.X && enemyRect.X > startingPos.X - (2 * enemyRect.Width) && !isMovingRight)
            {
                enemyRect = new Rectangle(enemyRect.X - 1, enemyRect.Y, enemyRect.Width, enemyRect.Height);
            }
            if (enemyRect.X == startingPos.X - (2 * enemyRect.Width))
            {
                isMovingRight = true;
            }

            if (isMovingRight && enemyRect.X <= startingPos.X + (2 * enemyRect.Width))
            {
                enemyRect = new Rectangle(enemyRect.X + 1, enemyRect.Y, enemyRect.Width, enemyRect.Height);
            }
            if (enemyRect.X == startingPos.X + (2 * enemyRect.Width))
            {
                isMovingRight = false;
            }

            if (enemyRect.Intersects(thePlayer.playerPosition) && this.isVisible)
            {
                thePlayer.isFighting = true;
            }
        }
    }
}
